<?php
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\LinkPager;
use yii\widgets\ActiveForm;
$this->title = '评价管理';
?>
<div class="container">
    <div class="row">
      
        <?php echo $this->render('_leftnav') ?>

        <div class="col-md-10">
          <div class="page-header clearfix">
            <h1 class="pull-left">资讯评论</h1>
            <div class="pull-right">

                                            
            </div>
          </div>
          
          
  <?php $form = ActiveForm::begin([
          'options'=>['class'=>"form-inline well well-sm"],
          'action'=>['operate/comsearch'],
          'method'=>'post',

]);?>     
    <div class="form-group">
      <input class="form-control" placeholder="作者" name="user_name" value="<?php if(!empty($user_name)){echo $user_name;}?>" type="text">
    </div>

    <div class="form-group">
      <input class="form-control" placeholder="评价内容关键词" name="comment_content" value="<?php if(!empty($comment_content)){echo $comment_content;}?>" type="text">
    </div>

    <button class="btn btn-primary" type="submit">搜索</button>
  <?php $form = ActiveForm::end();?>

  <div id="review-table-container">
    <table class="table table-striped table-hover" id="review-table">
      <thead>
        <tr>
          <th width="4%">ID</th>
          <th width="40%">评论内容</th>
          <th width="25%">作者</th>
          <th width="15%">状态</th>
          <th width="18%">操作</th>
        </tr>
      </thead>
      <tbody> 
                <?php foreach ($data as $key => $info) {?>
                  <tr>
                    <td width="4%"><?php echo $info['comment_id']?></td>
                    <td width="40%">
                      <?php
                        $str = $info['comment_content'];
                        if(strlen($str)<30){
                          echo $str;
                        }else{
                          $num = mb_substr($str,0,30,'utf-8');
                          $rrr = str_replace($str, $num.'...',$str);
                          echo $rrr;
                        }
                         
                      ?>
                    </td>
                    <td width="25%"><?php echo $info['user_name']?></td>
                    <?php if($info['comment_status']==1){?>
                    <td width="15%"><font color='green'>通过</font></td>
                    <?php }else{?>
                    <td width="15%"><font color='red'>未通过</font></td>
                    <?php }?>
                    <td width="18%">
                    <?php if($info['comment_status']==1){?>
                    <a href="javascript:;" class="btn btn-default btn-sm comupdate" m="<?php echo $info['comment_status']?>" name="<?php echo $info['comment_id'];?>">取消</a>
                  <?php }else{?>
                  <a href="javascript:;" class="btn btn-default btn-sm comupdate" m="<?php echo $info['comment_status']?>" name="<?php echo $info['comment_id'];?>">通过</a>

                  <?php }?>
        <a href="javascript:;" class="btn btn-default btn-sm deletetype" type="<?php echo $info['comment_id'];?>"><i class="glyphicon glyphicon-trash"></i> 删除</a></td>
                  </tr>
                <?php }?>
              </tbody>
    </table>
<?php echo LinkPager::widget([
              'pagination'=>$pages,
              'prevPageLabel' => "上一页",
              'nextPageLabel' => "下一页",
]);?>

  </div>

    

        </div>

          </div>
  </div>
<script>
  //资讯修改
  $(".comupdate").click(function(){
    var comment_id = $(this).attr('name');
    var comment_status = $(this).attr('m');
    $.ajax({
        type: "POST",
        url: "<?= Url::to(['operate/comupdate']);?>",
        data: "comment_id="+comment_id+"&comment_status="+comment_status,
        success:function(msg){
          var msg=JSON.parse(msg);
          if(msg.code==1){
            alert('ok');
            history.go(0);
          }else{
            alert('更改失败');
            history.go(0);
          }
        }
    });
  })

  //资讯删除
  $(".deletetype").click(function(){
    var comment_id = $(this).attr('type');
    $.ajax({
        type: "POST",
        url: "<?= Url::to(['operate/comdel']);?>",
        data: "comment_id="+comment_id,
        success:function(msg){  
          var msg=JSON.parse(msg);
          if(msg.code==1){
            alert('删除成功');
            history.go(0);
          }else{
            alert('删除失败');
            history.go(0);
          }
        }
    });
  })
</script>
